//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CBaseIndex10.cpp>
///	@path	~/src/graphics/dx10/
///	@date	2009/01/13
///	@desc	.

#include "config/config.h"

#include "graphics/dx10/CBaseIndex10.h"

namespace xeres {
	
	IMPL_IOBJECT_CLASS( CBaseIndex10 );

	// CBaseIndex10
	CBaseIndex10::CBaseIndex10( ID3D10Buffer * buffer , size_t count , DXGI_FORMAT format )
		: m_pBuffer( buffer )
		, m_count( count )
		, m_format( format )
	{
		m_pBuffer->GetDesc( &m_desc );
	}
	// ~CBaseIndex10
	CBaseIndex10::~CBaseIndex10( void )
	{
		if( m_pBuffer )
		{
			UINT rest = m_pBuffer->Release();
			if( rest != 0 )
			{
				TRACE_ERROR( _S("CBaseIndex10::DTOR: Invalid ID3D10Buffer reference count.") );
				FATAL_ABORT( _S("Invalid ID3D10Buffer reference count.") );
			}
		}
	}
	// OnLostDevice
	bool CBaseIndex10::OnLostDevice( void )
	{
		return true;
	}
	// OnResetDevice
	bool CBaseIndex10::OnResetDevice( RefWeak<IDevice> device )
	{
		return true;
	}
	// GetCount
	size_t CBaseIndex10::GetCount( void )
	{
		return m_count;
	}
	// GetSize
	size_t CBaseIndex10::GetSize( void )
	{
		return m_desc.ByteWidth;
	}
	// IsWritable
	bool CBaseIndex10::IsWritable( void )
	{
		return (m_desc.CPUAccessFlags & D3D10_CPU_ACCESS_WRITE) ? true : false;
	}
	// IsReadable
	bool CBaseIndex10::IsReadable( void )
	{
		return (m_desc.CPUAccessFlags & D3D10_CPU_ACCESS_READ) ? true : false;
	}
	// Map
	bool CBaseIndex10::Map( bool discard , ResourceMap& data )
	{
		TRACE_ERROR( _S("CBaseIndex10::Map: Not implemented.") );
		FATAL_ABORT( _S("Not implemented call.") );
		return false;
	}
	// ReadBack
	bool CBaseIndex10::ReadBack( ResourceMap& data , bool readonly )
	{
		TRACE_ERROR( _S("CBaseIndex10::ReadBack: Not implemented.") );
		FATAL_ABORT( _S("Not implemented call.") );
		return false;
	}
	// Unmap
	bool CBaseIndex10::Unmap( void )
	{
		TRACE_ERROR( _S("CBaseIndex10::Unmap: Not implemented.") );
		FATAL_ABORT( _S("Not implemented call.") );
		return false;
	}
	// GetVertexInterface
	IUnknown * CBaseIndex10::GetVertexInterface( void )
	{
		return NULL;
	}
	// GetIndexInterface
	IUnknown * CBaseIndex10::GetIndexInterface( void )
	{
		return m_pBuffer;
	}
	// GetFormat
	DXFormat CBaseIndex10::GetFormat( void )
	{
		return DXFormat( m_format );
	}
	// ApplyIndex
	void CBaseIndex10::ApplyIndex( RenderContext& rc )
	{
		rc.GetDX10()->IASetIndexBuffer( m_pBuffer , m_format , 0 );
	}
	
} // namespace xeres
